package cn.cold.face;

import java.util.LinkedList;

public class TaskState
{
  private LinkedList<Long> time = new LinkedList<Long>();
  private long MaxTime;
  private long MixTime;
  private Integer TaskCount = Integer.valueOf(0);
  private Integer TimeoutCount = Integer.valueOf(0);
  private Integer ErrorCount = Integer.valueOf(0);
  
  public LinkedList<Long> getTime()
  {
    return this.time;
  }
  
  public synchronized void setTime(long time)
  {
    this.time.add(Long.valueOf(time));
  }
  
  public long getMaxTime()
  {
    return this.MaxTime;
  }
  
  public synchronized void setMaxTime(long maxTime)
  {
    if (maxTime > this.MaxTime) {
      this.MaxTime = maxTime;
    }
  }
  
  public long getMixTime()
  {
    return this.MixTime;
  }
  
  public synchronized void setMixTime(long mixTime)
  {
    if (this.MixTime == 0L) {
      this.MixTime = mixTime;
    }
    if (mixTime < this.MixTime) {
      this.MixTime = mixTime;
    }
  }
  
  public Integer getTaskCount()
  {
    return this.TaskCount;
  }
  
  public synchronized void AddTaskCount()
  {
	  TaskCount = Integer.valueOf(this.TaskCount.intValue() + 1);
  }
  
  public synchronized void ReduceTaskCount()
  {
	  TaskCount = Integer.valueOf(this.TaskCount.intValue() - 1);
  }
  
  public long Avg()
  {
    long countTime = 0L;
    for (int i = 0; i < this.time.size(); i++) {
      countTime += ((Long)this.time.get(i)).longValue();
    }
    return countTime / this.time.size();
  }
  
  public long Sum()
  {
    long countTime = 0L;
    for (int i = 0; i < this.time.size(); i++) {
      countTime += ((Long)this.time.get(i)).longValue();
    }
    return countTime / this.time.size();
  }
  
  public Integer getTimeoutCount()
  {
    return this.TimeoutCount;
  }
  
  public void setTimeoutCount(Integer timeoutCount)
  {
    this.TimeoutCount = Integer.valueOf(this.TimeoutCount.intValue() + timeoutCount.intValue());
  }
  
  public Integer getErrorCount()
  {
    return this.ErrorCount;
  }
  
  public void setErrorCount(Integer errorCount)
  {
    this.ErrorCount = Integer.valueOf(this.ErrorCount.intValue() + errorCount.intValue());
  }
}
